package cn.edu.suda.catalina.health;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;

import cn.edu.suda.catalina.entity.Diary;

public class MasterActivity extends AppCompatActivity implements MenuFragment.OnMenuFragmentInteractionListener, DiaryFragment.OnDiaryFragmentInteractionListener, AnotherFragment.OnAnotherFragmentInteractionListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_master);

        getSupportFragmentManager().beginTransaction().add(R.id.activity_master, MenuFragment.newInstance()).commit();
    }

    @Override
    public void onMenuFragmentInteraction(Fragment fragment, String tag) {
        getSupportFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.activity_master, fragment, tag).commit();
    }

    @Override
    public void onDiaryFragmentInteraction() {
        AnotherFragment anotherFragment = (AnotherFragment) getSupportFragmentManager().findFragmentByTag(AnotherFragment.FRAGMENT_TAG);
        anotherFragment.DataSetChanged();
    }

    @Override
    public void onAnotherFragmentInteraction(Diary diary) {
        DiaryShowFragment fragment = DiaryShowFragment.newInstance();
        fragment.show(getFragmentManager(), DiaryShowFragment.FRAGMENT_TAG);
        fragment.setText(diary);
    }
}
